﻿using System.Linq;

namespace Nxg.Blog.Core.Commands.Posts {
    public class DeleteCommentCommand {
        public int CommentId { get; set; }
    }

    public class DeleteCommentCommandInvoker : ICommandInvoker<DeleteCommentCommand, CommandResult> {
        private readonly DataContext _db;

        public DeleteCommentCommandInvoker (DataContext db) {
            _db = db;
        }

        public CommandResult Execute (DeleteCommentCommand command) {
            var entity = _db.Comment.SingleOrDefault (x => x.Id == command.CommentId);
            _db.Remove (entity);
            _db.SaveChanges ();
            return CommandResult.SuccessResult;
        }
    }
}